<script setup>
import axios from 'axios'
import {  ref } from 'vue';
const list = ref([])

// !#1 获取数据
const getList = async () => {
  const { data } = await axios.get('/list')
  list.value = data
}
getList()

// !#2 删除数据
const delFn = async (id) => {
  await axios.delete('/del?id=' + id)
  getList()
}
</script>

<template>
  <div class="app">
    <el-table :data="list">
      <el-table-column label="ID" prop="id"></el-table-column>
      <el-table-column label="姓名" width="150" prop="name"></el-table-column>
      <el-table-column label="籍贯" prop="place"></el-table-column>
      <el-table-column label="操作" width="100">
        <template #default="{ row }">
          <el-button type="primary" link @click="delFn(row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<style>
.app {
  width: 980px;
  margin: 100px auto 0;
}
</style>